package yunhe.servlet;

import yunhe.biz.LoginBiz;
import yunhe.biz.impl.EmpMsgBizImpl;
import yunhe.biz.impl.LoginBizImpl;
import yunhe.entity.EmpMsg;
import yunhe.entity.UserLogin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "LoginServlet",urlPatterns = "/LoginServlet")
public class LoginServlet extends HttpServlet{

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	    String Id=req.getParameter("loginId");
		String Pwd=req.getParameter("loginPwd");
		
		LoginBiz biz=new LoginBizImpl();
		UserLogin user=new UserLogin();

		user.setWorkId(Id);
		user.setUserPwd(Pwd);

		UserLogin userLogin=biz.userLogin(user);
		HttpSession session=req.getSession();
		if (userLogin!=null) {
			EmpMsg em=new EmpMsgBizImpl().getEmpByWorkId(Id);
			session.setAttribute("user", em);
			resp.sendRedirect("index.jsp");
		}else {
			session.setAttribute("user", "false");
			resp.sendRedirect("login.jsp");
		}
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
	
}
